import mongoengine

from academic.settings import MONGODB


class Statistics(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('STATISTICS')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    month = mongoengine.StringField(db_field='月份', max_length=50, required=True)
    meeting = mongoengine.StringField(db_field='会议', max_length=50, required=True)

    def __str__(self):
        return "会议id" + str(self.id) + "\t 会议名称" + str(self.meeting)

class ThemesEmbedded(mongoengine.EmbeddedDocument):

    keywords = mongoengine.StringField(db_field='关键词', max_length=200)
    org = mongoengine.StringField(db_field='机构', max_length=50, null=True)
    speaker = mongoengine.StringField(db_field='演讲者', max_length=50, null=True)
    report = mongoengine.StringField(db_field='主题报告', max_length=50)

class Meetings(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('CONFERENCE')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    meeting = mongoengine.StringField(db_field='会议名称', max_length=50, required=True)
    introduction = mongoengine.StringField(db_field='2019年会议简介', max_length=100)
    location = mongoengine.StringField(db_field='举办地点', max_length=50, null=True)
    year = mongoengine.StringField(db_field='年份', max_length=50)
    time = mongoengine.StringField(db_field='时间', max_length=50, null=True)
    info = mongoengine.StringField(db_field='投稿信息', max_length=50, null=True)
    remindPartDate = mongoengine.StringField(db_field='邮件提醒参会日期', max_length=50, null=True)
    remindContributeDate = mongoengine.StringField(db_field='邮件提醒投稿日期', max_length=50, null=True)
    host = mongoengine.StringField(db_field='主办方', max_length=50, null=True)
    # 若删除其会议,使用reverse_delete_rule可将与其关联的主题报告也删除.
    themes = mongoengine.EmbeddedDocumentListField(db_field='主题', document_type=ThemesEmbedded, required=False)

    def __str__(self):
        return "2019会议id" + str(self.id) + "\t 会议名称" + str(self.meeting)

class Subjects(mongoengine.DynamicDocument):
    meta = {'collection': MONGODB.get('SUBJECT')}

    id = mongoengine.StringField(db_field='_id', max_length=50, primary_key=True)
    meeting = mongoengine.StringField(db_field='会议', max_length=50)
    keywords = mongoengine.StringField(db_field='关键词', max_length=200)
    org = mongoengine.StringField(db_field='机构', max_length=50, null=True)
    speaker = mongoengine.StringField(db_field='演讲者', max_length=50, null=True)
    report = mongoengine.StringField(db_field='主题报告', max_length=50)
